package com.xiaren.config;

import com.rabbitmq.client.Channel;
import com.xiaren.service.BookingService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;

/**
 * @Description 接收
 * @Author xiaren
 * @Date 18/12/22 10:06
 **/
@Slf4j
@Component
@Profile("rabbitmq_profiles")    // 方便不同环境测试
public class MqReciver {


    @Autowired
    BookingService bookingService;


    @Transactional
    @RabbitListener(queues = "directQueue")
    public void directListener(Message message, Channel channel) throws IOException {
        System.out.println(message);
        System.out.println(channel);

        doTransactional();

    }


    /**
     * 测试rabbitMQ
     */
    @Transactional
    public void doTransactional(){

        bookingService.book("aa");
        System.out.println(1/0);
    }
}
